﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sys.WebRes.Data;
using System.Text;

namespace Sys.WebRes.Publish.Areas.Admin.Controllers
{
    public class HomeController : Controller
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [OutputCache(NoStore=true)]
        public ActionResult Top()
        {
            return View();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult Left()
        {
            return PartialView();
        }

        public ActionResult JScript()
        {
            StringBuilder result = new StringBuilder();
            string resType = "";
            ResType.Map.Values.ToList().ForEach(p => {
                resType += string.Format("{{id:'{0}', name:'{1}'}},", p.ID, p.Name);
            });
            result.AppendFormat("resType=[{0}];", resType);

            string statusType = "";
            ResStatusType.Map.Values.ToList().ForEach(p =>
            {
                statusType += string.Format("{{id:'{0}', name:'{1}'}},", p.ID, p.Name);
            });
            result.AppendFormat("statusType=[{0}];", statusType);

            result.Append(@"
                function getComboboxFormatter(array) {
                    return function(value){
                        for (var i = 0; i < array.length; i++) {
                            if (array[i].id == value) {
                                return array[i].name;
                            }
	                    }
	                    return value;
                    }
	            }");






            return JavaScript(result.ToString());
        }
    }
}